package com.qls.web.modules.dt.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qls.core.entity.DtDt;
import com.qls.core.entity.DtStore;
import com.qls.core.entity.DtStorePf;
import com.qls.core.entity.OpGroup;
import com.qls.core.utils.R;
import com.qls.web.common.utils.PageUtils;
import com.qls.web.modules.dt.service.DtService;
import com.qls.web.modules.dt.service.StorePfService;
import com.qls.web.modules.dt.service.StoreService;
import com.qls.web.modules.op.service.GroupService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 销售平台
 *
 * @author yj
 * @email yj@gmail.com
 * @date 2021-09-04 11:21:52
 */
@RestController
@RequestMapping("dt/storepf")
public class StorePfController {
    @Autowired
    private StorePfService storePfService;

    @Autowired
    private DtService dtService;

    @Autowired
    private StoreService storeService;

    @Autowired
    private GroupService groupService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("dt:storepf:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = storePfService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("dt:storepf:info")
    public R info(@PathVariable("id") Integer id) {
        DtStorePf storePf = storePfService.getById(id);

        return R.ok().put("storePf", storePf);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("dt:storepf:save")
    public R save(@RequestBody DtStorePf storePf) {
        storePfService.save(storePf);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("dt:storepf:update")
    public R update(@RequestBody DtStorePf storePf) {
        storePfService.updateById(storePf);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("dt:storepf:delete")
    public R delete(@RequestBody Integer[] ids) {
        storePfService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }


    /**
     * 查找分销商
     */
    @RequestMapping("/query")
    public R getList() {
        List<DtDt> dts = dtService.getBaseMapper().selectList(new QueryWrapper<DtDt>());
        List<DtStorePf> spfs = storePfService.getBaseMapper().selectList(new QueryWrapper<DtStorePf>());
        return R.ok().put("spfs", spfs).put("dts", dts);
    }

    @RequestMapping("/store")
    public R getStore(@RequestParam Map<String, Object> params) {
        List<DtStore> sts = storeService.queryByDtId(params);
        return R.ok().put("sts", sts);
    }

    @RequestMapping("/group")
    public R getGroup(@RequestParam Map<String, Object> params) {
        List<OpGroup> gps = groupService.querygpByStoreId(params);
        return R.ok().put("gps", gps);
    }
}
